package com.bana.fvs.protocol;

import com.bana.fvs.model.VisibilityScale;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 查询能见度等级参数
 */
public class QueryVisibilityConfig {

    public int getId()
    {
        return 0x09;
    }

    public byte[] toBuffer(int kzqbsm)
    {
        byte[] buffer=new byte[4];
        buffer[0]=(byte)0x81;
        buffer[1]=(byte)kzqbsm;
        buffer[2]=(byte)0x09;
        buffer[3]=(byte)0xff;
        return buffer;
    }

    public List<VisibilityScale> toModel(byte[] buffer) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
        DataInputStream dis = new DataInputStream(bais);
        dis.skipBytes(3);
        List<VisibilityScale> visibilityScales=new ArrayList<>();
        //固定十个等级，每个等级12字节
        for(int i=0;i<10;++i)
        {
            VisibilityScale visibilityConfig=new VisibilityScale();
            visibilityConfig.setNjddj(dis.readByte());
            byte b1=dis.readByte();
            byte b2=dis.readByte();
            visibilityConfig.setWdkz(dis.readByte());
            visibilityConfig.setNjdsx(b2*128+b1);
            visibilityConfig.setWdld(dis.readByte());
            b1=dis.readByte();
            b2=dis.readByte();
            visibilityConfig.setLdsc(b2*128+b1);
            b1=dis.readByte();
            b2=dis.readByte();
            visibilityConfig.setMdsc(b2*128+b1);
            visibilityConfig.setHdys(dis.readByte());
            visibilityConfig.setMqys(dis.readByte());
            visibilityConfig.setHsjsdzsl(dis.readByte());
            visibilityScales.add(visibilityConfig);
        }
        dis.close();
        bais.close();
        return visibilityScales;
    }
}
